<?php
session_start();
//require_once("../config/include.inc.php");
require_once("../config/include_tokyo.inc.php");
require_once("../class/Core_Lib_Page.php");
require_once("../class/Common_Function.php");
$commonFunction = new Common_Function();


//get post value
$doFlag = $_POST["doFlag"];
$id = $_POST["id"];
$validateFlag = true;
$insertError = "";




//统计总数
$sql = "SELECT SUM(bank_amount) as bank_sum FROM banktransfer where owner_flag=0 and stauts_flag=0";
$result = $db->Execute($sql);	
if (empty($result) ||  $result->RecordCount() < 1) {	
	$vincent_sum = 0;
}else{
	$vincent_sum = $result->fields['bank_sum'];
}
$sql = "SELECT SUM(bank_amount) as bank_sum   FROM banktransfer where owner_flag=1 and stauts_flag=0";
$result = $db->Execute($sql);	
if (!empty($result)) {
	$liuyi_sum = $result->fields['bank_sum'];
}else{
	$liuyi_sum = 0;
}
$bank_self = 1612;//2012-12-17 百五上的利息
$bank_sum = $vincent_sum + $liuyi_sum +  $bank_self;



//分页设置
$list_rows = 30; //每页显示的记录数
if($doFlag == "showAll"){
	//全部显示
	$sql_list = "SELECT COUNT(*) as total_rows  from banktransfer"; 
}else if($doFlag == "doSearchDate"){
	//搜索: 按日期
	$bank_time_search =  $_POST["bank_time_search"];	
	$sql_list = "SELECT COUNT(*) as total_rows  from banktransfer where bank_time ='".$bank_time_search."' "; 
}else if($doFlag == "doSearchNote"){
	//搜索: 按摘要
	$bank_note_search =  $_POST["bank_note_search"];	
	$sql_list = "SELECT COUNT(*) as total_rows  from banktransfer where bank_note  like'%".$bank_note_search."%' "; 
}else if($doFlag == "doSearchTransfer"){
	//搜索: 按类型
	$transfer_flag_search =  $_POST["transfer_flag_search"];	
	$sql_list = "SELECT COUNT(*) as total_rows  from banktransfer where transfer_flag ='".$transfer_flag_search."' "; 
}else{
	//默认: 当前数据
	$sql_list = "SELECT COUNT(*) as total_rows  from banktransfer  where stauts_flag=0"; 
}
$result = $db->Execute($sql_list);
if (!empty($result)) {
	$totalRows = $result->fields['total_rows'];
}
$params = array(
	'total_rows'=>$totalRows,
	'list_rows'=>$list_rows,
	'method'    =>'ajax',
	'ajax_func_name' =>'goToPage',
	'now_page' => !empty($_POST['nowPage']) ? $_POST['nowPage'] : 1 
);
$page = new Core_Lib_Page($params);
$limit_m = $page->first_row;
$limit_n = $list_rows;


//get bank list,默认只列出 stauts_flag=0的,0=正常显示 1=历史数据
if($doFlag == "showAll"){
	//全部显示
	$sql_select = "select * from banktransfer order by bank_time desc,modifytime desc limit $limit_m,$limit_n";
}else if($doFlag == "doSearchDate"){
	//搜索: 按日期
	$bank_time_search =  $_POST["bank_time_search"];	
	$sql_select = "select * from banktransfer where bank_time ='".$bank_time_search."'  order by bank_time desc,modifytime desc limit $limit_m,$limit_n";
}else if($doFlag == "doSearchNote"){
	//搜索: 按摘要
	$bank_note_search =  $_POST["bank_note_search"];	
	$sql_select = "select * from banktransfer where bank_note  like'%".$bank_note_search."%' order by bank_time desc,modifytime desc limit $limit_m,$limit_n";
}else if($doFlag == "doSearchTransfer"){
	//搜索: 按类型
	$transfer_flag_search =  $_POST["transfer_flag_search"];	
	$sql_select = "select * from banktransfer where transfer_flag='".$transfer_flag_search."' order by bank_time desc,modifytime desc limit $limit_m,$limit_n";
}else{
	//默认: 当前数据
	$sql_select = "select * from banktransfer where  stauts_flag=0 order by bank_time desc,modifytime desc limit $limit_m,$limit_n";
}
$result = $db->Execute($sql_select);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "银行转帐列表"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>





<form name="listForm" action="bankList.php" method="post">
<div id="container" >	




<div class="grayTable">	
<h4>新增银行记录:
<a href="https://www.105direct.105bank.com/WBIG0000.html" target="_blank">百五</a> 1763308176
</h4>
<p><font color='red'><b>从2013.5.1开始,vincent停止百五收款。(很少老客户可能还会直接银行付款)</b></font></p>

<?php
$currentDate = date('Y-m-d',time());
if(!$validateFlag){
	echo "<font color='red'>新增记录出错: ".$insertError."</font>";
}
?>



<!----------------查询记录----------------------------->
<table >
<thead>
<tr>
<td>时间</td><td><input type="text" name="bank_time_search" id="bank_time_search" value="<?php echo $currentDate;?>" size=8></td><td><input type="button" name="搜索" value="搜索" onclick="doSearchDate()"></td>
<td>摘要</td><td><input type="text" name="bank_note_search" id="bank_note_search"  size=8></td><td><input type="button" name="搜索" value="搜索" onclick="doSearchNote()"></td>
<td>类型</td><td><select name="transfer_flag_search" id="transfer_flag_search"><option value=2  >疑问</option><option value=0  >转入</option><option value=1  >转出</option><option value=3  >归总</option></select></td><td><input type="button" name="搜索" value="搜索" onclick="doSearchTransfer()"></td>
</tr>
</thead>
</table>

<h4>
<a href='/bank/bankList.php' >当前统计:</a>
(Vincent[<?php echo $commonFunction->toMoney($vincent_sum);?>]
<!--
+
LiuYi[<?php echo $commonFunction->toMoney($liuyi_sum);?>]
+
BankSelf[<?php echo $commonFunction->toMoney($bank_self);?>]
 =
百五[<?php echo $commonFunction->toMoney($bank_sum);?>] )
-->
</h4>


<!----------------记录list----------------------------->
<table >
<thead>
	<tr>
		<th scope="col" width=30>编号</th>
		<th scope="col" width=80>时间</th>
	    <th scope="col" width=60>金额</th>
		<th scope="col" >摘要</th>
		<th scope="col" width=60>归属</th>
		<th scope="col" >备注</th>
		<th scope="col" >类型</th>

	</tr>
</thead>

<tbody>	
	<?php	
	if(empty($result) || $result->RecordCount() < 1){
		echo "<tr><td colspan=10 align='center'>记录为空.</td></tr>";
	}else{
		while (!$result->EOF) {	
			$owner = $result->fields['owner_flag'];
			if($owner == 0){
				$owner = "Vincent";
			}else if($owner == 1){
				$owner = "LiuYi";
			}else{
				$owner = "未知";
			}
			$transfer_name = $result->fields['transfer_flag'];
			$importantClass = "class='important'";
			if($transfer_name == 0){
				$transfer_name = "转入";
				$importantClass = "";
			}else if($transfer_name == 1){
				$transfer_name = "转出";
			}else if($transfer_name == 2){
				$transfer_name = "疑问";
			}else if($transfer_name == 3){
				$transfer_name = "归总";
			}else{
				$transfer_name = "未知";
			}
			$stauts_flag_str = '';
			$stauts_flag = $result->fields['stauts_flag'];
			if($stauts_flag  == 1){
				$stauts_flag_str = "<br>(历史记录)";
			}else{
				$stauts_flag_str = '';
			}
			$strTR = "<tr  ".$importantClass." >";
			$strTR = $strTR."<td>".$result->fields['id']."</td>";
			$strTR = $strTR."<td>".date('Y-m-d',strtotime($result->fields['bank_time']))."</td>";
			$strTR = $strTR."<td>".$commonFunction->toMoney($result->fields['bank_amount'])."</td>";
			$strTR = $strTR."<td>".$result->fields['bank_note']."</td>";
			$strTR = $strTR."<td>".$owner."</td>";
			$strTR = $strTR."<td>".$result->fields['our_note']."</td>";
			$strTR = $strTR."<td>".$transfer_name.$stauts_flag_str."</td>";

			$strTR = $strTR."</tr>";
			echo $strTR;
			$result->MoveNext();
		}
	}
	?>
</tbody>	


					
</table>	
<br>
<!--Page 分页 -->
<div id="page"><?php echo $page->show(2);?></div>

<div class="clearBoth">&nbsp;</div>



</div>



</div><!--end container -->

<input type="hidden" name="doFlag" id="doFlag" value="<?php echo $doFlag; ?>">
<input type="hidden" name="id" id="id" value="<?php echo $id; ?>">
<input type="hidden" name="nowPage" id="nowPage" value="<?php echo $nowPage; ?>">
</form>

</body>




</html>



